import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

class Todo {
  final String title;
  final String description;

  Todo(this.title, this.description);
}

class  FirstScreen extends StatelessWidget{
  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(
        title: new Text('第一个页面'),
        backgroundColor: Colors.red,
      ),
      body: Builder(
          builder: (BuildContext context){
            return new Center(
              child: new RaisedButton(
                  child: new Text('跳转'),
                  onPressed: (){
                    _navigateAndDisplaySelection(context);
                  }
              ),
            );
          }
      )
    );
  }

  // A method that launches the SelectionScreen and awaits the result from
  // Navigator.pop
  _navigateAndDisplaySelection(BuildContext context) async {
    // Navigator.push returns a Future that will complete after we call
    // Navigator.pop on the Selection Screen!
    final result = await Navigator.push(
      context,
      // We'll create the SelectionScreen in the next step!
      new MaterialPageRoute(builder: (context) => new SecondScreen(todo: Todo("我是界面1", "ss"))),
    );
//
    final snackBar = new SnackBar(content: new Text(result.toString()));

    Scaffold.of(context).showSnackBar(snackBar);
  }

}


class SecondScreen extends StatelessWidget {
  // Declare a field that holds the Todo
  final Todo todo;
  SecondScreen({Key key, @required this.todo}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(
        title: new Text('第二个页面'),
        backgroundColor: Colors.brown,
      ),
      body: new Center(
        child: new RaisedButton(
          onPressed: () {
            Navigator.pop(context,"界面二收到");
          },
          child: new Text('收到${todo.title},点击返回'),
        ),
      ),
    );
  }
}
